home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / time / backclock.lha / backclock / sources / style / graph.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  2.9 KB  |  120 lines

  1. #include <stdio.h>
  2. #include <intuition/intuition.h>
  3. #include <intuition/screens.h>
  4. #include <libraries/gadtools.h>
  5. #include <clib/intuition_protos.h>
  6. #include <clib/exec_protos.h>
  7. #include <clib/graphics_protos.h>
  8. #include <clib/rtracker_protos.h>
  9. #include <clib/exec_protos.h>
  10. #include <clib/dos_protos.h>
  11. #include <clib/gadtools_protos.h>
  12. #include <pragmas/rtracker_pragmas.h>
  13. #include <exec/libraries.h>
  14. #include <exec/memory.h>
  15. #include <dos/dos.h>
  16.  
  17. #include "main.h"
  18. #include "graph.h"
  19.  
  20. extern struct Library * RTrackerBase ;
  21. extern struct Library * GadToolsBase ;
  22.  
  23. extern SPoint * ipoint, * current ;
  24.  
  25. void DrawGrid(struct Window * win) {
  26.   struct RastPort * rport ;
  27.   ULONG offx, offy ;
  28.   ULONG i ;
  29.  
  30.   offx = win->BorderLeft ;
  31.   offy = win->BorderTop ;
  32.   rport = win->RPort ;
  33.   SetAPen(rport, 0) ;
  34.   RectFill(rport, win->BorderLeft, win->BorderTop,
  35.                   win->BorderLeft+WIDTH, win->BorderTop+HEIGHT) ;
  36.   SetAPen(rport, 2) ;
  37.   for(i = 0; i< WIDTH; i += GRID) {
  38.     Move(rport, i + offx, offy) ;
  39.     Draw(rport, i + offx, HEIGHT + offy) ;
  40.   }
  41.   for(i = 0; i< HEIGHT; i += GRID) {
  42.     Move(rport, offx, i + offy) ;
  43.     Draw(rport, WIDTH + offx, i + offy) ;
  44.   }
  45.   SetAPen(rport, 3) ;
  46.   RectFill(rport, computeX(win, 104)-2, computeY(win, 144)-2,
  47.                   computeX(win, 104)+2, computeY(win, 144)+2) ;
  48.  
  49. }
  50.  
  51. ULONG computeX(struct Window *win, ULONG x) {
  52.   /* transform normal X to window X
  53.    */
  54.   x = x / GRID ;
  55.   x = x * GRID + win->BorderLeft ;
  56.   return(x) ;
  57. }
  58. ULONG computeY(struct Window *win, ULONG y) {
  59.   /* transform normal Y to window Y
  60.    */
  61.   y = y / GRID ;
  62.   y = y * GRID + win->BorderTop ;
  63.   return(y) ;
  64. }
  65.  
  66. void DrawArrow(struct Window * win) {
  67.   /* redraw the figure
  68.    */
  69.   SPoint * cp ;
  70.   struct RastPort * rport ;
  71.  
  72.  
  73.   DrawGrid(win) ;
  74.   cp = ipoint->next ;
  75.   if (cp) {
  76.     /* al least 1 point exists
  77.      */
  78.     rport = win->RPort ;
  79.     /* move to the first point
  80.      */
  81.     SetAPen(rport, 1) ; // set the black color
  82.     Move(rport, computeX(win, cp->x+PX),
  83.                 computeY(win, cp->y+PY)) ;
  84.     /* draw the lines
  85.      */
  86.  
  87.     while(cp) {
  88.       Draw(rport, computeX(win, cp->x+PX),
  89.                   computeY(win, cp->y+PY)) ;
  90.       if (cp == current)
  91.         SetAPen(rport, 2) ; // change the colour for the current point
  92.       
  93.       RectFill(rport, computeX(win, cp->x+PX)-2, computeY(win, cp->y+PY)-2,
  94.                       computeX(win, cp->x+PX)+2, computeY(win, cp->y+PY)+2 ) ;
  95.       cp = cp->next ;
  96.       SetAPen(rport, 1) ;
  97.     }
  98.   }
  99.  
  100. }
  101.  
  102. void DrawPoint(struct Window * win, WORD x, WORD y) {
  103.   /* draw a point at X,Y on the grid (with mouse coords)
  104.    */
  105.   struct RastPort * rport ;
  106.  
  107.   rport = win->RPort ;
  108.   /* set posiotn using the grid
  109.    */
  110.  
  111.   x = x - win->BorderLeft + (GRID / 2) ;
  112.   y = y - win->BorderTop +  (GRID / 2) ;
  113.   x = x / GRID ;
  114.   y = y / GRID ;
  115.   x = x * GRID + win->BorderLeft ;
  116.   y = y * GRID + win->BorderTop ;
  117.   SetAPen(rport, 1) ;
  118.   RectFill(rport, x-2, y-2, x+2, y+2) ;
  119. }
  120.